<template lang="pug">
md-button.btn-sm.btn.btn-primary.pull-right.btn-round(@click='onClick') 删除
</template>

<script>
import axios from 'axios'

export default {
  name: 'DeviceDeleteButton',
  props: {
    value: {
      _id: String,
      iccid: String
    },
    index: Number
  },
  methods: {
    deleteDevice() {
      axios.delete(process.env.API_URL + '/ysj/id/' + this.value._id)
      .then((response) => this.$emit('delete', this.index))
      .catch((error) => console.log(error))
    },
    onClick() {
      console.log('this.index', this.index)
      let result = confirm(`是否要删除设备 ${this.value.iccid}?`)
      if (result) {
        this.deleteDevice()
      }
    }
  }
}
</script>

